﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                    xmlns:converters="clr-namespace:myCollections.Utils">

    <converters:RectConverter x:Key="RectConverter"></converters:RectConverter>
    
    <Style x:Key="MyProgressBarStyle" TargetType="{x:Type ProgressBar}">
        <Setter Property="Foreground" Value="#FF06B025"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid x:Name="TemplateRoot" SnapsToDevicePixels="true">
                        <TextBlock Text="{TemplateBinding Tag}" Grid.ZIndex="2" Foreground="Black"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"/>
                        <TextBlock Text="{TemplateBinding Tag}"
                                Grid.ZIndex="3" Foreground="White"
                                Width="{Binding ElementName=rectangle, Path=ActualWidth}"
                                TextAlignment="Center"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Center">
                            <TextBlock.Clip>
                                <RectangleGeometry>
                                    <RectangleGeometry.Rect>
                                        <MultiBinding Converter="{StaticResource RectConverter}">
                                            <Binding ElementName="Indicator" Path="ActualWidth"/>
                                            <Binding ElementName="Indicator" Path="ActualHeight"/>
                                        </MultiBinding>
                                    </RectangleGeometry.Rect>
                                </RectangleGeometry>
                            </TextBlock.Clip>
                        </TextBlock>
                        <Rectangle x:Name="rectangle" Fill="{TemplateBinding Background}" RadiusY="2" RadiusX="2"/>
                        <Border Background="{DynamicResource ProgressBarGlassyHighlight}" CornerRadius="2" Margin="1"/>
                        <Border BorderBrush="#80FFFFFF" BorderThickness="1,0,1,1" Background="{DynamicResource ProgressBarTopHighlight}" Margin="1"/>
                        <Rectangle x:Name="PART_Track" Margin="1"/>
                        <Decorator x:Name="PART_Indicator" HorizontalAlignment="Left" Margin="1">
                            <Grid x:Name="Foreground">
                                <Rectangle x:Name="Indicator" Fill="{TemplateBinding Foreground}"/>
                                <Grid x:Name="Animation" ClipToBounds="true">
                                    <Rectangle x:Name="PART_GlowRect" Fill="{DynamicResource ProgressBarIndicatorAnimatedFill}" HorizontalAlignment="Left" Margin="-100,0,0,0" Width="100"/>
                                </Grid>
                                <Grid x:Name="Overlay">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition MaxWidth="15"/>
                                        <ColumnDefinition Width="0.1*"/>
                                        <ColumnDefinition MaxWidth="15"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Rectangle x:Name="LeftDark" Fill="{DynamicResource ProgressBarIndicatorDarkEdgeLeft}" Margin="1,1,0,1" RadiusY="1" RadiusX="1" Grid.RowSpan="2"/>
                                    <Rectangle x:Name="RightDark" Grid.Column="2" Fill="{DynamicResource ProgressBarIndicatorDarkEdgeRight}" Margin="0,1,1,1" RadiusY="1" RadiusX="1" Grid.RowSpan="2"/>
                                    <Rectangle x:Name="LeftLight" Grid.Column="0" Fill="{DynamicResource ProgressBarIndicatorLightingEffectLeft}" Grid.Row="2"/>
                                    <Rectangle x:Name="CenterLight" Grid.Column="1" Fill="{DynamicResource ProgressBarIndicatorLightingEffect}" Grid.Row="2"/>
                                    <Rectangle x:Name="RightLight" Grid.Column="2" Fill="{DynamicResource ProgressBarIndicatorLightingEffectRight}" Grid.Row="2"/>
                                    <Border x:Name="Highlight1" Background="{DynamicResource ProgressBarIndicatorGlassyHighlight}" Grid.ColumnSpan="3" Grid.RowSpan="2"/>
                                    <Border x:Name="Highlight2" Background="{DynamicResource ProgressBarTopHighlight}" Grid.ColumnSpan="3" Grid.RowSpan="2"/>
                                </Grid>
                            </Grid>
                        </Decorator>
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Vertical">
                            <Setter Property="LayoutTransform" TargetName="TemplateRoot">
                                <Setter.Value>
                                    <RotateTransform Angle="-90"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="true">
                            <Setter Property="Visibility" TargetName="LeftDark" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="RightDark" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="LeftLight" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="CenterLight" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="RightLight" Value="Collapsed"/>
                            <Setter Property="Visibility" TargetName="Indicator" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="IsIndeterminate" Value="false">
                            <Setter Property="Background" TargetName="Animation" Value="#80B5FFA9"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>